import {UPDATE_MODULES_LIST, LOAD_MODULES_LIST} from '../actions'

export default function themeModulesReducer(state = {}, action) {
    const {list} = action

    //give uid for list item
    switch (action.type) {
        case UPDATE_MODULES_LIST:
            const {data} = list
            let modules = {}
            let modulesToString  = ""
            for (let i = 0; i < data.length; i++) {
                modules[data[i].moduleId] = data[i].moduleName
            }
            modulesToString = Object.keys(modules).toString()
            return {
                ...state,
                data: {
                    ...list
                },
                modules,
                modulesToString
            }
        default:
            return state
    }
}